package cn.edu.cdu.health.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/openai")
public class ChatController {

    @Autowired
    @Qualifier("openAiChatModel")
    private ChatModel chatModel;

    @Autowired
    private ChatClient chatClient;


   /* @GetMapping("/chat")
    @Operation(summary = "聊天流式调用")
    public Flux<String> chat(@RequestParam String msg) {
        Flux<String> stream = chatModel.stream(msg);
        return stream;
    }*/

    @GetMapping("/chat")
    @Operation(summary = "openai聊天流式调用")
    public Flux<String> chat2(@RequestParam String msg) {
        Flux<String> stream = chatClient.prompt().user(msg)
                .stream().content();
        return stream;
    }

}